<?php

function magic_modifier_truncate($string, $length = '20'){
  if ($length == 0) {    return '';}
  $ext='';
  if(stristr($length,':'))
  {
   $var=explode(':',$length);
   $length=$var[0];
   $ext=$var[1];
   $type=$var[2];
   if($type=='e')
   {
	   $var2=explode('@',$string);
	   $num=strlen($var2[0]);
	   $star='';
	   for($i=0;$i<$num;$i++)
	   {
		   $star.='*';
		}
		
		return $star.'@'.$var2[1];
	}
  }
    $pa = "/[\x01-\x7f]|[\xa1-\xff][\xa1-\xff]/";


    preg_match_all($pa, $string, $t_string);
    if (count($t_string[0]) > $length)

        return join('', array_slice($t_string[0], 0, $length)).$ext;

    return join('', array_slice($t_string[0], 0, $length)).$ext;



   $tmpstr = "";
    for($i = 0; $i < $strlen; $i++) {
        if(ord(substr($string, $i, 1)) > 0xa0) {
            $tmpstr .= substr($string, $i, 2);
            $i++;
        } else
            $tmpstr .= substr($string, $i, 1);
    }
    return $tmpstr;
	

}
?>
